#include <iostream>

using namespace std;

typedef unsigned long long LL;
const int N = 1e6 + 10;

int top;
LL stk[N];

int main()
{
    int T; cin >> T;
    while(T--)
    {
        // 清空栈
        top = 0;

        int n; cin >> n;
        while(n--)
        {
            string op; cin >> op;
            if(op == "push") // 入栈
            {
                LL x; cin >> x;
                stk[++top] = x;
            }
            else if(op == "pop") // 出栈
            {
                if(top == 0) cout << "Empty" << endl;
                else top--;
            }
            else if(op == "query") // 查询
            {
                if(top == 0) cout << "Anguei!" << endl;
                else cout << stk[top] << endl;
            }
            else // 栈的大小
            {
                cout << top << endl;
            }
        }
    }

    return 0;
}